package com.atguigu.utils;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

//获取redis的jedis连接池和jedis连接
public class JedisUtil {
    private static JedisPool jedisPool;
    static {
        JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
        jedisPoolConfig.setMaxWaitMillis(2000);
        jedisPoolConfig.setMaxTotal(100);
        jedisPoolConfig.setMaxIdle(5);
        jedisPoolConfig.setMinIdle(5);
        jedisPoolConfig.setTestOnBorrow(true);
        jedisPoolConfig.setBlockWhenExhausted(true);

        jedisPool=new JedisPool(jedisPoolConfig,"hadoop102",6379,10000);
    }

    public static Jedis getJedis(){
        //获取jedis连接
        Jedis jedis = jedisPool.getResource();
        return jedis;
    }

}
